//
//  YDMyCardHeaderTableViewCell.m
//  IngCard
//
//  Created by kf on 2017/8/11.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YDMyCardHeaderView.h"

@interface YDMyCardHeaderView()
@property(nonatomic, strong) UIImageView *backgroundImageView;

@property(nonatomic, strong) UIButton *searchButton;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UIButton *plusButton;

@property(nonatomic, strong) UIImageView *headerImageView;
@property(nonatomic, strong) UIImageView *oriImageView;

@property(nonatomic, strong) UILabel *userNameLabel;
@property(nonatomic, strong) UILabel *userTitleLabel;

@property(nonatomic, strong) UILabel *userPhoneLabel;
@property(nonatomic, strong) UIImageView *userPhoneImageView;

@property(nonatomic, strong) UILabel *userEmailLabel;
@property(nonatomic, strong) UIImageView *userEmailImageView;

@property(nonatomic, strong) UILabel *userLocationLabel;
@property(nonatomic, strong) UIImageView *userLocationImageView;

@property(nonatomic, strong) UIButton *syncButton;

@property(nonatomic, strong) UIView *lineView1;
@property(nonatomic, strong) UILabel *syncLabel;
@property(nonatomic, strong) UIView *lineView2;

@end
@implementation YDMyCardHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initSubviews];
    }
    return self;
}




-(void) initSubviews
{
    [self addSubview:self.backgroundImageView];
    [self.backgroundImageView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0);
        make.top.equalTo(-200);//self.contentView).offset(0);
        make.height.equalTo(325);
    }];
    
    [self addSubview:self.searchButton];
    [self.searchButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(30);
        make.top.equalTo(33);
    }];
    
    [self addSubview:self.titleLabel];
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.searchButton);
    }];
    
    [self addSubview:self.plusButton];
    [self.plusButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.searchButton);
        make.right.equalTo(self).offset(-30);
    }];
    
    [self addSubview:self.headerImageView];
    [self.headerImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(106);
        make.left.equalTo(88);
        make.width.equalTo(77);
        make.height.equalTo(77);
    }];
    
    [self addSubview:self.oriImageView];
    [self.oriImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerImageView);
        make.right.equalTo(self).offset(-87);
    }];
    
    
    [self addSubview:self.userNameLabel];
    [self.userNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerImageView);
        make.top.equalTo(self.headerImageView.mas_bottom).offset(13);
    }];
    
    [self addSubview:self.userTitleLabel];
    [self.userTitleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userNameLabel);
        make.top.equalTo(self.userNameLabel.mas_bottom).offset(4);
    }];

    [self addSubview:self.userPhoneImageView];
    [self.userPhoneImageView makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.oriImageView);
        make.top.equalTo(self.headerImageView.mas_bottom).offset(10);
    }];
    
    [self addSubview:self.userPhoneLabel];
    [self.userPhoneLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.userPhoneImageView.mas_left).offset(-13);
        make.centerY.equalTo(self.userPhoneImageView);
    }];
    
    [self addSubview:self.userEmailImageView];
    [self.userEmailImageView makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.userPhoneImageView);
        make.top.equalTo(self.userPhoneImageView.mas_bottom).offset(6);
    }];
    
    [self addSubview:self.userEmailLabel];
    [self.userEmailLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.userPhoneLabel);
        make.centerY.equalTo(self.userEmailImageView);
    }];
    
    [self addSubview:self.userLocationImageView];
    [self.userLocationImageView makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.userPhoneImageView);
        make.top.equalTo(self.userEmailImageView.mas_bottom).offset(6);
    }];
    
    [self addSubview:self.userLocationLabel];
    [self.userLocationLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.userPhoneLabel);
        make.centerY.equalTo(self.userLocationImageView);
    }];
    
    [self addSubview:self.syncButton];
    [self.syncButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.backgroundImageView.mas_bottom).offset(221);
        make.width.equalTo(251);
        make.height.equalTo(44);
    }];
    
    [self addSubview:self.syncLabel];
    [self.syncLabel makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(-18);
        make.centerX.equalTo(self);
        make.width.equalTo(60);
        make.height.equalTo(21);
    }];
    
    [self addSubview:self.lineView1];
    [self.lineView1 makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.syncLabel.mas_left).offset(-20);
        make.centerY.equalTo(self.syncLabel);
        make.width.equalTo(123);
        make.height.equalTo(2);
    }];
    
    [self addSubview:self.lineView2];
    [self.lineView2 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.syncLabel.mas_right).offset(20);
        make.centerY.equalTo(self.syncLabel);
        make.width.equalTo(123);
        make.height.equalTo(2);
    }];
}

-(void) onViewModelChanged
{
    
}

#pragma mark - private
- (void)searchButtonAction:(UIButton *)btn
{
    
}

- (void)plusButtonAction:(UIButton *)btn
{
    
}
- (void)syncButtonAction:(UIButton *)btn
{
    BlockGoGo(self.sync);
}

#pragma mark - lazy loading

-(UIImageView *) backgroundImageView
{
    if (!_backgroundImageView)
    {
        _backgroundImageView = [UIImageView new];
        UIImage *image = UIImageMake(@"myCard_backgourd");
        CGFloat width =  image.size.width;
        CGFloat height = image.size.height;
        
        _backgroundImageView.image = [image qmui_imageWithScaleToSize:CGSizeMake(SCREEN_WIDTH, (SCREEN_WIDTH * height) /width) contentMode:UIViewContentModeScaleToFill];
        _backgroundImageView.contentMode = UIViewContentModeCenter;
        
        [_backgroundImageView sizeToFit];
    }
    return _backgroundImageView;
}

-(UIButton *) searchButton
{
    if (!_searchButton)
    {
        _searchButton = [[UIButton alloc] init];
        _searchButton.frame = CGRectMake(0, 0, 15, 17);
        [_searchButton setBackgroundImage:UIImageMake(@"myCard_search") forState:UIControlStateNormal];
        _searchButton.layer.masksToBounds = YES;
        [_searchButton addTarget:self
                          action:@selector(searchButtonAction:)
                forControlEvents:UIControlEventTouchUpInside];
    }
    return _searchButton;
}

- (UILabel *) titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"我的智能名片";
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = UIFontLightMake(20);
        _titleLabel.textColor = UIColorWhite;
        [_titleLabel sizeToFit];
    }
    return _titleLabel;
}

-(UIButton *)plusButton
{
    if (!_plusButton)
    {
        _plusButton = [[UIButton alloc] init];
        _plusButton.frame = CGRectMake(0, 0, 15, 15);
        [_plusButton setBackgroundImage:UIImageMake(@"myCard_plus") forState:UIControlStateNormal];
        _plusButton.layer.masksToBounds = YES;
        [_plusButton addTarget:self
                          action:@selector(plusButtonAction:)
                forControlEvents:UIControlEventTouchUpInside];
    }
    return _plusButton;
}

-(UIImageView *) headerImageView
{
    if (!_headerImageView)
    {
        _headerImageView = [UIImageView new];
        _headerImageView.image = UIImageMake(@"myCard_userHeader");
        _headerImageView.contentMode = UIViewContentModeCenter;
        [_headerImageView sizeToFit];
    }
    return _headerImageView;
}

-(UIImageView *) oriImageView
{
    if (!_oriImageView)
    {
        _oriImageView = [UIImageView new];
        _oriImageView.image = UIImageMake(@"myCard_ori");
        _oriImageView.contentMode = UIViewContentModeCenter;
        [_oriImageView sizeToFit];
    }
    return _oriImageView;
}

- (UILabel *)userNameLabel
{
    if (!_userNameLabel)
    {
        _userNameLabel = [[UILabel alloc] init];
        _userNameLabel.text = @"Shipeng Li";
        _userNameLabel.textAlignment = NSTextAlignmentLeft;
        _userNameLabel.font = UIFontBoldMake(14);
        _userNameLabel.textColor = UIColorBlack;
        [_userNameLabel sizeToFit];
    }
    return _userNameLabel;
}

- (UILabel *) userTitleLabel
{
    if (!_userTitleLabel)
    {
        _userTitleLabel = [[UILabel alloc] init];
        _userTitleLabel.text = @"Chief Technology Officer";
        _userTitleLabel.textAlignment = NSTextAlignmentLeft;
        _userTitleLabel.font = UIFontLightMake(9);
        _userTitleLabel.textColor = UIColorBlack;
        [_userTitleLabel sizeToFit];
    }
    return _userTitleLabel;
}

- (UILabel *) userPhoneLabel
{
    if (!_userPhoneLabel)
    {
        _userPhoneLabel = [[UILabel alloc] init];
        _userPhoneLabel.text = @"021-2823944";
        _userPhoneLabel.textAlignment = NSTextAlignmentRight;
        _userPhoneLabel.font = UIFontLightMake(9);
        _userPhoneLabel.textColor = UIColorBlack;
        [_userPhoneLabel sizeToFit];
    }
    return _userPhoneLabel;
}


-(UIImageView *) userPhoneImageView
{
    if (!_userPhoneImageView)
    {
        _userPhoneImageView = [UIImageView new];
        _userPhoneImageView.image = UIImageMake(@"myCard_phone");
        _userPhoneImageView.contentMode = UIViewContentModeCenter;
        [_userPhoneImageView sizeToFit];
    }
    return _userPhoneImageView;
}

- (UILabel *) userEmailLabel
{
    if (!_userEmailLabel)
    {
        _userEmailLabel = [[UILabel alloc] init];
        _userEmailLabel.text = @"sample@gmail.com";
        _userEmailLabel.textAlignment = NSTextAlignmentRight;
        _userEmailLabel.font = UIFontLightMake(9);
        _userEmailLabel.textColor = UIColorBlack;
        [_userEmailLabel sizeToFit];
    }
    return _userEmailLabel;
}


-(UIImageView *) userEmailImageView
{
    if (!_userEmailImageView)
    {
        _userEmailImageView = [UIImageView new];
        _userEmailImageView.image = UIImageMake(@"myCard_email");
        _userEmailImageView.contentMode = UIViewContentModeCenter;
        [_userEmailImageView sizeToFit];
    }
    return _userEmailImageView;
}

-(UILabel *) userLocationLabel
{
    if (!_userLocationLabel)
    {
        _userLocationLabel = [[UILabel alloc] init];
        _userLocationLabel.text = @"Hai Dian, Beijing";
        _userLocationLabel.textAlignment = NSTextAlignmentRight;
        _userLocationLabel.font = UIFontLightMake(9);
        _userLocationLabel.textColor = UIColorBlack;
        [_userLocationLabel sizeToFit];
    }
    return _userLocationLabel;
}

-(UIImageView *) userLocationImageView
{
    if (!_userLocationImageView)
    {
        _userLocationImageView = [UIImageView new];
        _userLocationImageView.image = UIImageMake(@"myCard_location");
        _userLocationImageView.contentMode = UIViewContentModeCenter;
        [_userLocationImageView sizeToFit];
    }
    return _userLocationImageView;
}

-(UIButton *) syncButton
{
    if (!_syncButton)
    {
        _syncButton = [[UIButton alloc] init];
        _syncButton.frame = CGRectMake(0, 0, 251, 44);
        [_syncButton setBackgroundColor:UIColorMake(102, 186, 141)];
        _syncButton.layer.cornerRadius = 6;
        [_syncButton setTitle:@"同步" forState:(UIControlStateNormal)];
        _syncButton.titleLabel.font = UIFontMake(15);
        _syncButton.layer.masksToBounds = YES;
        [_syncButton addTarget:self
                          action:@selector(syncButtonAction:)
                forControlEvents:UIControlEventTouchUpInside];
    }
    return _syncButton;
}


- (UILabel *) syncLabel
{
    if (!_syncLabel)
    {
        _syncLabel = [[UILabel alloc] init];
        _syncLabel.text = @"最近同步";
        _syncLabel.textAlignment = NSTextAlignmentCenter;
        _syncLabel.font = UIFontLightMake(15);
        _syncLabel.textColor = UIColorBlack;
        [_syncLabel sizeToFit];
    }
    return _syncLabel;
}

- (UIView *) lineView1
{
    if (!_lineView1)
    {
        _lineView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 123, 2)];
        _lineView1.backgroundColor = UIColorMake(151, 151, 151);
    }
    return _lineView1;
}
- (UIView *) lineView2
{
    if (!_lineView2)
    {
        _lineView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 123, 2)];
        _lineView2.backgroundColor = UIColorMake(151, 151, 151);
    }
    return _lineView2;
}
@end
